package GUILayer;

import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JTextField;

public class GuiHelper {
	
	public static void displayError(String message)
	{
		displayMessage("Fejl", message);
	}
	
	public static void displayMessage(String title, String message)
	{
		displayMessage(title, message, null);
	}
	
	public static void displayMessage(String title, String message, JFrame frameToCloseAfterClosing)
	{
		JDialog dialog = new JDialog();
		dialog.setTitle(title);
		dialog.add(new JTextField(message));
		dialog.setSize(300, 200);
		dialog.setVisible(true);
		
		if (frameToCloseAfterClosing != null) {
			dialog.addWindowListener(new WindowAdapter() {
				@Override
				public void windowClosing(WindowEvent arg0) {
					frameToCloseAfterClosing.dispatchEvent(new WindowEvent(frameToCloseAfterClosing, WindowEvent.WINDOW_CLOSING));
				}
			});
		}
	}
}
